#!/usr/bin/python
import cgi
import string
import os,sys
import traceback
from PageMaker import HTMLPage




print "Content-type: text/html"
print

#print "<html>"
#print "<head><title>VITSystem</title></head>"
#print "<body>"

myPage = HTMLPage()
myPage.addTitle("VITSystem Login Screen")
myPage.addForm("vatsindex.html","post","mainForm")
fs = cgi.FieldStorage()
user_auth = 1
user_name = fs.getvalue("log_id")
pswd = fs.getvalue("pswd")
print user_name,pswd
try:
	f = open("user_info.txt","r")
	for line in f:
		tempInfo = line.strip()
		tempLine = tempInfo.split("|")
		if tempLine[0] == user_name:
			if tempLine[1] == pswd:
				user_auth = 0
	if user_auth == 0:
		myPage.addElement("User has been authenticated","","","")
		#print "User authenticated"
	else:
		myPage.addElement("Sorry, unable to authenticate.  Please try again","","","")
		#print "Sorry, login failed.  Please try again"
	f.close()
	myPage.addElement("","submit","Continue","Continue")
	myPage.printForm()
except:
	print "Unable to open file"
	etype = sys.exc_info()[0]
	evalue = sys.exc_info()[1]
	etb = traceback.extract_tb(sys.exc_info()[2])

	print "etype=",str(etype)
	print "evalue=",str(evalue)
	print "traceback",str(etb)

